package util

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

// 返回结构体
type Response struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

// 初始化response
func NewResponseSuccess() *Response {
	return &Response{
		Code: 200,
		Msg:  "success",
		Data: make(map[string]interface{}),
	}
}

// 初始化response
func NewResponseFailed() *Response {
	return &Response{
		Code: 422,
		Msg:  "failed",
		Data: make(map[string]interface{}),
	}
}

// ResponseSuccess 统一返回json处理
func ResponseSuccess(c *gin.Context, response *Response) {
	c.JSON(http.StatusOK, response)
}

// 未认证
func ResponseUnAuth(c *gin.Context, response *Response) {
	c.JSON(http.StatusUnauthorized, response)
}
